/**
 * 
 */
package com.cap.cfae;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.eos.foundation.data.DataObjectUtil;
import com.eos.foundation.database.DatabaseUtil;
import com.eos.system.annotation.Bizlet;

import commonj.sdo.DataObject;

/**
 * @author zp
 * @date 2018-02-05 23:36:10
 *
 */
@Bizlet("")
public class TagBondService {
	
	@Bizlet("add")
	public Map<String,String>  addTagBond(String tagId,String bondId)
	{
		Map<String,String> result=new HashMap<String, String>();
		 DataObject  tagBond = DataObjectUtil.createDataObject("com.cap.cfae.cfae.TagBonds");
		 tagBond.set("id", getUUID());
		 tagBond.set("tagId",tagId);
		 tagBond.set("bondId", bondId);
		 try{
			 DatabaseUtil.insertEntity("default", tagBond);
			 result.put("code", "0");
			 result.put("msg", "添加标签和债券关系成功");
		 }catch(Exception e){
			 result.put("code", "1");
			 result.put("msg", "添加标签和债券关系失败");
			 e.printStackTrace();
		 }
		 
		 return result;
		
	}
	
	public String getUUID()
	{
		String uuid = UUID.randomUUID().toString(); 
		uuid = uuid.replace("-", "");    
		return uuid;
	}
	
	@Bizlet("update")
	public Map<String,String> updateTagBond(String id,String tagId,String bondId)
	{
		Map<String,String> result=new HashMap<String, String>();
		DataObject  tagBond = DataObjectUtil.createDataObject("com.cap.cfae.cfae.TagBonds");
		tagBond.set("id",id);
		tagBond.set("tagId",tagId);
		tagBond.set("bondId", bondId);
		 try{
			 DatabaseUtil.updateEntity("default", tagBond);
			 result.put("code", "0");
			 result.put("msg", "更新标签和债券关系成功");
		 }catch(Exception e){
			 result.put("code", "1");
			 result.put("msg", "更新标签和债券关系失败");
			 e.printStackTrace();
		 }
		 
		 return result;		
	}
	@Bizlet("delete")
	public Map<String,String> deleteTagBondById(String id)
	{
		Map<String,String> result=new HashMap<String, String>();
		DataObject  tagBond = DataObjectUtil.createDataObject("com.cap.cfae.cfae.TagBonds");
		tagBond.set("id",id);
		 try{
			 DatabaseUtil.deleteEntity("default", tagBond);
			 result.put("code", "0");
			 result.put("msg", "删除标签和债券关系成功");
		 }catch(Exception e){
			 result.put("code", "1");
			 result.put("msg", "删除标签和债券关系失败");
			 e.printStackTrace();
		 }
		 return result;		
	}

	public List<Map<String,String>> getListByTagId(String tagId)
	{
		DataObject  tagBond = DataObjectUtil.createDataObject("com.cap.cfae.cfae.TagBonds");
		tagBond.set("tagId",tagId);
		DataObject[]  tagBonds=DatabaseUtil.queryEntitiesByTemplate("default", tagBond);
		//获取对应的债券信息返回给前段
		return  null;
	}
}
